﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client;

namespace Cherrs.IM.Client
{
    public class SendText
    {
        public delegate void OnAllMesage(string context);
        public event OnAllMesage AllMesageEvent;
        protected virtual void OnAllMessage(string context) { AllMesageEvent.Invoke(context); }
        private BaseCon _con;
        public SendText(BaseCon con)
        {
            _con = con;
            _con.ChatHub.On<string>("all", OnAllMessage);
        }
        public Task<ErrorMessage> Send(string conetxt)
        {
            _con.hc.Start().Wait();
            return _con.ChatHub.Invoke("Send", conetxt).ContinueWith(p=> {
                ErrorMessage em = new ErrorMessage();
                if (p.IsCompleted)
                {
                    _con.hc.Stop();
                }
                
                return em;


            });
        }


    }
}
